﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;


    public class Common
    {


        public static void ResizeImage(System.Drawing.Image image, int newwidthimg, string filepath)
        {
            try
            {
                //int newwidthimg = image.Size.Width;
                float AspectRatio = (float)image.Size.Width / (float)image.Size.Height;
                int newHeight = Convert.ToInt32(newwidthimg / AspectRatio);
                Bitmap thumbnailBitmap = new Bitmap(newwidthimg, newHeight);
                Graphics thumbnailGraph = Graphics.FromImage(thumbnailBitmap);
                thumbnailGraph.CompositingQuality = CompositingQuality.HighQuality;
                thumbnailGraph.SmoothingMode = SmoothingMode.HighQuality;
                thumbnailGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
                var imageRectangle = new Rectangle(0, 0, newwidthimg, newHeight);
                thumbnailGraph.DrawImage(image, imageRectangle);
                thumbnailBitmap.Save(filepath, ImageFormat.Jpeg);
                thumbnailGraph.Dispose();
                thumbnailBitmap.Dispose();
                image.Dispose();
            }
            catch (Exception ex)
            {

            }

        }

        public static string CurrentUserName
        {
            get
            {
                string _CurrentUserName = "";
                try
                {
                    if (HttpContext.Current.User.Identity.IsAuthenticated) _CurrentUserName = HttpContext.Current.User.Identity.Name;
                    return _CurrentUserName;
                }
                catch { return _CurrentUserName; }
            }
        }

        public static string getUrl()
        {
            string sPath = HttpContext.Current.Request.Url.AbsoluteUri;
            sPath = sPath.Substring(sPath.LastIndexOf("/") + 1);
            sPath = HttpContext.Current.Request.Url.AbsoluteUri.Replace(sPath,"");
            return sPath;
        }


    }

